<%-- 
  - Author: Neha Chauhan
  - Date: 25-Mar-2011
  - Copyright Notice: TRAKHEES
  - Description: form.jsp
 --%>

<%@ include file="/WEB-INF/view/include.jsp"%>
<%@ page import="ae.pcfc.etks.online.web.*"%>
<c:if
	test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
	<script language="Javascript"
		src='<c:url value="/resources/js/ui/jquery.ui.datepicker-ar.js"/>'></script>
</c:if>
<script type="text/javascript">
	
	function del() 
	{		
		var row = $(this).parent().parent().prevAll().length;
		var confirmMsg = '<spring:message code="form.doc.delete.confirm" />';
		jConfirm(confirmMsg,'<spring:message code="label.button.delete" />',function(result){
			if(result){
				try{
					deleteFile(row);
					var tr = $("#docTable").find("tr").get(row); 
					$(tr).remove();
				}catch(e){}
			}	
		});
		return false;
	}
	function deleteFile(row) 
	{		
		$("input:hidden[name^='arrDocumentVOs["+row+"]']").remove();
		resetArrDocs(row);
	}
	function resetArrDocs(index){
		try{
			for(var nextIndex=parseInt(index)+1;nextIndex<2;nextIndex++){
				var nextElmts = $("input:hidden[name^='arrDocumentVOs["+ nextIndex + "]']");
				if(nextElmts == null ||nextElmts.length == 0){
					return;
				}else{
					for(var elmtIdx=0;elmtIdx<nextElmts.length;elmtIdx++){
						var elmt = nextElmts[elmtIdx];
						var elmtName = $(elmt).attr('name');
						elmtName = elmtName.replace(nextIndex, nextIndex-1);
						var elmtVal = $(elmt).val();
						var newElmt = $("<input type='hidden' name='" + elmtName + "' value='" + elmtVal + "'>");
						$("#docElmts").append(newElmt);
						$(elmt).remove();
					}
				}
			}
		}catch(e){
			return false;
		}
	}

	$().ready(function() {
		//$( "input:submit, input:reset, input:button, input:file").button();
		$(".deleteDoc").live("click",del);
		$("#strUploadDocumentType,#strAuthorizedPerson").change(function(){
		    var value = $("#strUploadDocumentType").val();
		    var authPerson = $("#strAuthorizedPerson:checked");
			if(value == 'PWER_ATRNY' && authPerson.length>0){
				$("label[for='strUploadDocumentType']").find("span").hide();
			}else{
				$("label[for='strUploadDocumentType']").find("span").show();
			}
			if(value == 'PWER_ATRNY'){
				$("#idCopyMsg").hide();
			}else{
				$("#idCopyMsg").show();
			}
		});
		
		$("#RegisteredUser").validate({
			onfocusout:false,
			onkeyup:false,
			//onclick: false,			
			rules : {
				strCompNameEng : "required",
				strCompNameArab : "required",
				strUserName : "required",
				strEmailAddress : "required",
				strPassword : {required:true, minlength:8, maxlength:12},
				strConfirmPassword : {required:true,equalTo: "#strPassword"},
				iSecQuestion : "required",
				strSecAnswer : "required",
				strMobileNumber : "required",
				strUploadDocumentType : "required"
				
				
			},
			showErrors : function(errorMap, errorList) {

				var errors = '<ul>';
				var label;
				if (errorList.length) {
					$.each(errorMap, function(name, value) {
						label = $("label[for='" + name + "']").html();
						label = value + '[' + label + ']';
						errors = errors + '<li>' + label + '</li>';

					});
					errors = errors + '</ul>';
					jAlert('error', errors, '<spring:message code="label.errormessage" />');
				}
			}

		});
		$("#strUploadDocumentType").trigger("change");
	
	});
	
</script>
<style type="text/css">
#idCopyMsg ol{
	padding-left:15px;
	padding-right: 15px;
}
#idCopyMsg ol li{
	list-style:square;
}

</style>
<div id="container" dir='<spring:message code="page.dir"/>'
	align='<spring:message code="page.align"/>'>
<form:form name="RegisteredUser" id="RegisteredUser" method="POST" enctype="multipart/form-data"
		modelAttribute="<%=ConstantsAdmin.CLIENT_COMPANY_REGISTRATION_INFO_REQUEST_MODEL_KEY %>">
		
		<spring:hasBindErrors
			name="<%=ConstantsAdmin.CLIENT_COMPANY_REGISTRATION_INFO_REQUEST_MODEL_KEY %>">
			<script type="text/javascript">
				$(document)
						.ready(
								function() {
									jAlert(
											'error',
											$('<code>'+'<li><form:errors path="*" delimiter="<li>"/>'+'</code>').text(),
											'<spring:message code="label.errormessage" />');
								});
			</script>
		</spring:hasBindErrors>
		 
		 
		
	<div class="ui-widget_c ui-corner-all">
		<div class="ui-jqgrid-titlebar ui-widget-header ui-corner-top ui-helper-clearfix"><spring:message code="label.client.summary.info" /></div>
       	<div class="ui-widget_content_c t_fin-black-txt">
		<fieldset><legend><spring:message
		code="label.company.nameinfo" /></legend>	
		</fieldset>	
		<div class="t_form-left">
			<div class="fm-req"><label>
				<spring:message code="label.company.nameeng" />
				</label> <input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strNameENG}"></c:out>'>
				<br/>			
			</div>
			<div class="fm-req"><label>
					<spring:message code="label.company.namearab" />
				</label> <input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strNameARB}"></c:out>'>
				<br/>		
			</div>
			<div class="fm-req"><label>
				<spring:message code="label.company.telnooffice" />
				</label><input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strOfficeNo}"></c:out>'>
				<br/>			
			</div>
			<div class="fm-req"><label>
				<spring:message code="label.company.role" />
				</label>
				<select multiple="multiple" style="float: none;height:100px;" disabled="disabled" class="fm-opt">	
				<c:forEach items="${clientCompanySummary.SCClientCompanyRoleVO}" var="clientRole" varStatus="loop">
					<c:choose>
						<c:when	test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
							<option><c:out value="${clientRole.clientRoleArb}"></c:out></option>
						</c:when>
						<c:otherwise>
							<option><c:out value="${clientRole.clientRoleEng}"></c:out></option>
						</c:otherwise>
					</c:choose>		
					<br/>				 
				</c:forEach>
				</select>	
			</div>
			<br/>
			
			<div class="fm-req"><label>
				<spring:message code="label.company.emailaddress" />
				</label><input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strEmail}"></c:out>'>
				<br/>			
			</div>
			
			<div><label>
				<spring:message code="label.company.websiteurl" />
				</label><input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strWebsite}"></c:out>'>
				<br/>			
			</div>
		</div>
		<fieldset><legend><spring:message code="label.company.licenseinfo" /></legend>	</fieldset>
		<div class="t_form-left">
		<div class="fm-req"><label>
			<spring:message code="label.company.lia" />
			</label>
			<c:choose>
				<c:when
					test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
					<input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strLicIADescAr}"></c:out>'>
				</c:when>
				<c:otherwise>
					<input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strLicIADescEn}"></c:out>'>
				</c:otherwise>
			</c:choose>
			<br/>			
		</div>
		
		<div class="fm-req"><label>
			<spring:message code="label.company.lno" />
			</label><input
						disabled="disabled"
						value='<c:out value="${clientCompanySummary.strLicenseNumber}"></c:out>'>
			<br/>			
		</div>
		
		<div class="fm-req"><label>
			<spring:message code="label.company.lid" />
			</label><input
						disabled="disabled"
						value='<fmt:formatDate pattern="dd-MM-yyyy"  value="${clientCompanySummary.strLicenseIssueDate}"></fmt:formatDate>'>
			<br/>			
		</div>
		
		<div class="fm-req"><label>
			<spring:message code="label.company.led" />
			</label><input
						disabled="disabled"
						value='<fmt:formatDate pattern="dd-MM-yyyy" value="${clientCompanySummary.strLicenseExpiryDate}"></fmt:formatDate>'>
			<br/>			
		</div>
		
	</div>
			
		<fieldset>
		   <legend><spring:message code="label.login.details" /></legend>
		 	</fieldset>
		 <div class="t_form-left">
		 
		 <div class="fm-req">
		 
				<form:label path="strCompNameEng"><span class="t_star">*</span><spring:message code="label.adminname.eng" /></form:label>
				<form:input path="strCompNameEng" id="strCompNameEng" size="30"
					maxlength="100" />
		</div>
			
			
		<div class="fm-req">
		
				<form:label path="strCompNameArab"><span class="t_star">*</span><spring:message code="label.adminname.arab" /></form:label>
				<form:input path="strCompNameArab" id="strCompNameArab" size="30"
					maxlength="100" />
		</div>
		 
		 <div class="fm-req">	
				
				    
					<form:label path="strUserName" >
					<span class="t_star">*</span>
					  <spring:message code="label.username" />
					</form:label>
					<form:input path="strUserName" id="strUserName" size="20" maxlength="100" />	
				    
			</div>
		
			<div class="fm-req">	
				
				    
					<form:label path="strPassword" >
					<span class="t_star">*</span>
					  <spring:message code="label.password" />
					</form:label>
					<form:password path="strPassword" id="strPassword" size="20" maxlength="100" showPassword="true"/>	
				    
			</div>
		
		<div class="fm-req">	
				
				    
					<form:label path="strConfirmPassword" >
					<span class="t_star">*</span>
					  <spring:message code="label.confirmpassword" />
					</form:label>
					<form:password path="strConfirmPassword" id="strConfirmPassword" size="20" maxlength="100" showPassword="true"/>	
				    
		</div>
		
		<div class="fm-req">	
				
				    
					<form:label path="iSecQuestion" >
					<span class="t_star">*</span>
					  <spring:message code="label.secretquestion" />
					</form:label>
					<c:choose>
					<c:when	test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
						<form:select path="iSecQuestion"
							items="${userSecretQuestion}"
							id="iSecQuestion" itemLabel="labelAr" itemValue="id" class="fm-opt"/>
					</c:when>
					<c:otherwise>
						<form:select path="iSecQuestion"
							items="${userSecretQuestion}"
							id="iSecQuestion" itemLabel="labelEn" itemValue="id" class="fm-opt"/>
					</c:otherwise>
				</c:choose>		
				    
		</div>
		
		<div class="fm-req">	
				
				    
					<form:label path="strSecretAnswer" >
					<span class="t_star">*</span>
					  <spring:message code="label.anstosecretquestion" />
					</form:label>
					<form:input path="strSecretAnswer" id="strSecretAnswer" size="20" maxlength="100" />	
				    
		</div>
		<div>	
					<form:label path="strAuthorizedPerson" >
					<span class="t_star">*</span>
					<spring:message code="label.company.authorized.person" />
					</form:label>
					<div class="fm-multi">
							<form:checkbox path="strAuthorizedPerson" value="Y" id="strAuthorizedPerson" class="opt-input"/>
							<img class="tooltip"
						src='<c:url value="resources/images/question.png"/>'
						title="<spring:message code="msg.client.company.admin.doc.reqd" />"> 
					</div>
		</div>
		<div class="fm-req">	
				
				    
					<form:label path="strEmailAddress" >
					<span class="t_star">*</span>
					  <spring:message code="label.emailaddress" />
					</form:label>
					<form:input path="strEmailAddress" id="strEmailAddress" size="20" maxlength="100" />	
				    
		</div>
		
		<div class="fm-req">	
				
				    
					<form:label path="strMobileNumber" >
					<span class="t_star">*</span>
					  <spring:message code="label.mobilenumber" />
					</form:label>
					<form:input path="strMobileNumber" id="strMobileNumber" size="20" maxlength="100" />	
				    
		</div>
		
		
		<div style="display:none;">	
				
				    
					<form:label path="strMobileNotification" >
					  <spring:message code="label.company.notification" />
					</form:label>
							<div class="fm-multi">
		
									<spring:message code="label.emailnotification" /><form:hidden path="strEmailNotification" value="Y" id="strEmailNotification" class="opt-input"/> 
									<spring:message code="label.smsnotification" /><form:checkbox path="strMobileNotification" value="Y" id="strMobileNotification" class="opt-input"/>
							</div>
		
		</div>

		 <div class="fm-gen" >
					
				
				    <form:label path="strUploadDocumentType" >
				    <span class="t_star">*</span>
					   <spring:message code="label.company.uploaddocumentstype" />
					</form:label>
					<c:choose>
						<c:when
							test='${requestScope.requestContextAttribute.locale.language == "ar"}'>
							<form:select path="strUploadDocumentType"
								items="${nonClientRegistrationUploadDocumentType}"
								id="strUploadDocumentType" itemLabel="labelAr" itemValue="id" cssStyle="width:200px;" class="fm-opt"/>
						</c:when>
						<c:otherwise>
							<form:select path="strUploadDocumentType"
								items="${nonClientRegistrationUploadDocumentType}"
								id="strUploadDocumentType" itemLabel="labelEn" itemValue="id" cssStyle="width:200px;" class="fm-opt"/>
						</c:otherwise>
					</c:choose>
				</div>		
				<div style="display:none;" id="idCopyMsg" class="clear grid-grey-txt">
					<spring:message code="msg.upload.identification.copy" />
				</div>			
				    
	     <br>
			
			 <div class="fm-req">
				<%
				if ((request.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null)
								|| (request.getAttribute(ConstantsAdmin.ERROR_PARAM) != null)) {
					if (request.getAttribute(ConstantsAdmin.SUCCESS_PARAM) != null) {
				%>
				<h4>
					<%
						String doc = (String) request
											.getAttribute(ConstantsAdmin.SUCCESS_PARAM);
						if (doc.equals("IDNTY_COPY")) {
					%>
					<spring:message code="label.company.identification.copy" />
					<%
						} else if (doc.equals("PWER_ATRNY")) {
					%>
					<spring:message code="label.company.powerofattorney" />
					<%
						}
					%>
						<spring:message code="succss.document.upload" />
				</h4>
				<%
					}
				}
				%>			 
				<input type="file" id="files[0]" name="files[0]" size="25" style="width: 250px;"/>
				<input class="submit" type="submit" name="Upload"
						value="<spring:message code="label.button.upload" />" />
	 	
			</div>
				<div style="clear:both"></div>
				<div id="fm-req">
					<table id="docTable">
						<c:forEach
							items="${clientCompanyRegistrationInfo.arrDocumentVOs}"
							var="mapping" varStatus="loop">
							<tr class="${mapping.strUploadDocumentType}">
								<c:choose>
									<c:when test="${mapping.strUploadDocumentType == 'IDNTY_COPY'}">
										<td><spring:message code="label.company.identification.copy" />
										</td>
										<td width="10px"></td>
										<td><a
											href="file/tempview.htm?tempFileName=${mapping.strTempFileName}"
											class="view"><spring:message
													code="label.user.request.view" />
										</a>
										</td>
										<td>
										<a
											href="#" class="deleteDoc"><spring:message
													code="label.button.delete" />
										</a>
										</td>
									</c:when>
									<c:otherwise>
										<td><spring:message
												code="label.company.powerofattorney" />
										</td>
										<td width="10px"></td>
										<td><a
											href="file/tempview.htm?tempFileName=${mapping.strTempFileName}"
											class="view"><spring:message
													code="label.user.request.view" />
										</a>
										</td>
										<td>
										<a
											href="#" class="deleteDoc"><spring:message
													code="label.button.delete" />
										</a>
										</td>
										<br>
										<br>
									</c:otherwise>
								</c:choose>
							</tr>

						</c:forEach>
					</table>
				</div>
			<span id="docElmts">
			<c:forEach
				items="${clientCompanyRegistrationInfo.arrDocumentVOs}"
				var="mapping" varStatus="loop">
				<form:hidden path="arrDocumentVOs[${loop.index}].strName"
					value="${arrDocumentVOs.strName}"
					class="${mapping.strUploadDocumentType}" />
				<form:hidden path="arrDocumentVOs[${loop.index}].URL"
					value="${arrDocumentVOs.URL}"
					class="${mapping.strUploadDocumentType}" />
				<form:hidden
					path="arrDocumentVOs[${loop.index}].strUploadDocumentType"
					value="${arrDocumentVOs.strUploadDocumentType}"
					class="${mapping.strUploadDocumentType}" />
				<form:hidden path="arrDocumentVOs[${loop.index}].strTempFileName"
					value="${arrDocumentVOs.strTempFileName}"
					class="${mapping.strUploadDocumentType}" />
				<form:hidden path="arrDocumentVOs[${loop.index}].strExtension"
					value="${arrDocumentVOs.strExtension}"
					class="${mapping.strUploadDocumentType}" />
			</c:forEach>
			</span>
			<form:hidden path="strUploadURL"/>
            
              <div id="fm-submit" class="fm-req">
			    <input type="submit" name="submit" value="<spring:message code="label.button.submit" />" class="t_btns submit"/>
                <input type="reset" name="reset" value="<spring:message code="label.button.reset" />" class="t_btns reset"/>
			</div>
		</div>

	</div>
</div>
	
	
	
	</form:form>
</div>	
